package com.jingdianjichi.auth.service.Impl;

import com.jingdianjichi.auth.bo.AuthPermissionBO;
import com.jingdianjichi.auth.common.enums.IsDeletedFlagEnum;
import com.jingdianjichi.auth.convert.AuthPermissionBOConverter;
import com.jingdianjichi.auth.convert.AuthRoleBOConverter;
import com.jingdianjichi.auth.entity.AuthPermission;
import com.jingdianjichi.auth.mapper.AuthPermissionDao;
import com.jingdianjichi.auth.service.AuthPermissionDomainService;
import com.jingdianjichi.auth.service.AuthPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class AuthPermissionDomainServiceImpl implements AuthPermissionDomainService {
    @Resource
    private AuthPermissionService authPermissionService;

    /**
     * 新增权限
     *
     * @param authPermissionBO
     * @return
     */
    @Override
    public Boolean add(AuthPermissionBO authPermissionBO) {
        AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.converterBOToEntity(authPermissionBO);
        authPermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        Integer count =  authPermissionService.insert(authPermission);
        return count>0;
    }

    /**
     * 修改权限
     *
     * @param authPermissionBO
     * @return
     */
    @Override
    public Boolean update(AuthPermissionBO authPermissionBO) {
        AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.converterBOToEntity(authPermissionBO);
        Integer count = authPermissionService.update(authPermission);
        return count>0;
    }

    /**
     * 删除权限
     *
     * @param authPermissionBO
     * @return
     */
    @Override
    public Boolean delete(AuthPermissionBO authPermissionBO) {
        AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.converterBOToEntity(authPermissionBO);
        authPermission.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        Integer count = authPermissionService.update(authPermission);
        return count>0;
    }

}
